package talayaco.gui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

import talayaco.enums.TipoMovimientoEnum;
import talayaco.interfaz.GestionAlimentosINT;
import talayaco.utils.DateUtils;
import talayaco.utils.ErrorUtils;
import talayaco.utils.StringUtils;

public class EgresoAlimentos extends javax.swing.JInternalFrame {

	private static final long serialVersionUID = -5836838566559789958L;

	/** Creates new form EgresoAlimentos */
	public EgresoAlimentos() {
		initComponents();
	}

	private void initComponents() {

		jPanel1 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		listadoAlimentos = new javax.swing.JComboBox();
		jLabel2 = new javax.swing.JLabel();
		cantidad = new javax.swing.JTextField();
		unidad = new javax.swing.JLabel();
		botonAgregar = new javax.swing.JButton();
		botonEliminar = new javax.swing.JButton();
		jScrollPane1 = new javax.swing.JScrollPane();
		tablaEgresos = new javax.swing.JTable();
		botonAceptar = new javax.swing.JButton();
		botonCancelar = new javax.swing.JButton();
		jPanel2 = new javax.swing.JPanel();
		jLabel3 = new javax.swing.JLabel();
		fecha = new javax.swing.JTextField();
		jLabel4 = new javax.swing.JLabel();
		listadoEgreso = new javax.swing.JComboBox();
		jLabel5 = new javax.swing.JLabel();
		i = 0;
		tipoAlimento = "";
		unidadAlimento = "";
		tipoEgreso = "";

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		this.setTitle("Egreso de Alimentos");
		this.setResizable(false);

		jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
				"Detalles Egreso",
				javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
				javax.swing.border.TitledBorder.DEFAULT_POSITION,
				new java.awt.Font("Tahoma", 0, 11))); // NOI18N
		jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
				"Detalles Alimentos",
				javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
				javax.swing.border.TitledBorder.DEFAULT_POSITION,
				new java.awt.Font("Tahoma", 0, 11))); // NOI18N
		jPanel1.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N

		jLabel1.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		jLabel1.setText("Tipo de Alimento");

		jLabel3.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		jLabel3.setText("Fecha del Egreso");

		jLabel4.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		jLabel4.setText("Tipo de Egreso");

		fecha.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		fecha.setText("");

		listadoEgreso.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		listadoEgreso.setModel(new javax.swing.DefaultComboBoxModel(
				TipoMovimientoEnum.getTiposEgreso()));
		listadoEgreso.addItemListener(new java.awt.event.ItemListener() {
			public void itemStateChanged(java.awt.event.ItemEvent evt) {
				listadoEgresoItemStateChanged(evt);
			}
		});

		try {
			listadoAlimentos.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
			listadoAlimentos.setModel(new javax.swing.DefaultComboBoxModel(
					GestionAlimentosINT.getNombreAlimentos()));
			listadoAlimentos.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent evt) {
					listadoAlimentosItemStateChanged(evt);
				}
			});
		} catch (Exception e) {
			e.printStackTrace();
			JOptionPane.showMessageDialog(this, ErrorUtils.ERROR_INESPERADO,
					"ERROR INESPERADO", JOptionPane.ERROR_MESSAGE);
			this.dispose();
		}

		jLabel2.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		jLabel2.setText("Cantidad");

		jLabel5.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		jLabel5.setText("DD/MM/AAAA");

		cantidad.setText("");

		unidad.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		unidad.setText("");
		unidad.setEnabled(false);

		botonAgregar.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		botonAgregar.setText("Agregar");
		botonAgregar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				botonAgregarActionPerformed(evt);
			}
		});

		botonEliminar.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		botonEliminar.setText("Eliminar");
		botonEliminar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				botonEliminarActionPerformed(evt);
			}
		});

		tabla = new String[][] { { "", "", "", "" }, { "", "", "", "" },
				{ "", "", "", "" }, { "", "", "", "" }, { "", "", "", "" },
				{ "", "", "", "" }, { "", "", "", "" }, { "", "", "", "" },
				{ "", "", "", "" }, { "", "", "", "" }, { "", "", "", "" },
				{ "", "", "", "" }, { "", "", "", "" }, { "", "", "", "" },
				{ "", "", "", "" },

		};

		tablaEgresos.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		tablaEgresos.setModel(new javax.swing.table.DefaultTableModel(tabla,
				new String[] { "Alimento", "Cantidad", "Unidad", "Egreso" }) {
			private static final long serialVersionUID = 1L;

			@Override
			public boolean isCellEditable(int fila, int columna) {
				return false;
			}
		});
		jScrollPane1.setViewportView(tablaEgresos);

		DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
		tcr.setHorizontalAlignment(SwingConstants.CENTER);
		tablaEgresos.getColumnModel().getColumn(0).setCellRenderer(tcr);
		tablaEgresos.getColumnModel().getColumn(1).setCellRenderer(tcr);
		tablaEgresos.getColumnModel().getColumn(2).setCellRenderer(tcr);
		tablaEgresos.getColumnModel().getColumn(3).setCellRenderer(tcr);

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout
				.setHorizontalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																false)
														.addComponent(
																jScrollPane1,
																javax.swing.GroupLayout.Alignment.LEADING,
																0, 0,
																Short.MAX_VALUE)
														.addGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																jPanel1Layout
																		.createSequentialGroup()
																		.addGroup(
																				jPanel1Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								jLabel1)
																						.addComponent(
																								jLabel2))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				jPanel1Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								listadoAlimentos,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addGroup(
																								jPanel1Layout
																										.createSequentialGroup()
																										.addComponent(
																												cantidad,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												53,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												unidad,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												54,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addGap(18,
																				18,
																				18)
																		.addGroup(
																				jPanel1Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								false)
																						.addComponent(
																								botonEliminar,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								botonAgregar))))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		jPanel1Layout
				.setVerticalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel1)
														.addComponent(
																listadoAlimentos,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																botonAgregar))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel2)
														.addComponent(
																cantidad,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(unidad)
														.addComponent(
																botonEliminar))
										.addGap(18, 18, 18)
										.addComponent(
												jScrollPane1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												134,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		botonAceptar.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		botonAceptar.setText("Aceptar");
		botonAceptar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				botonAceptarActionPerformed(evt);
			}
		});

		botonCancelar.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		botonCancelar.setText("Cancelar");
		botonCancelar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				botonCancelarActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout
				.setHorizontalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel3)
														.addComponent(jLabel4))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																false)
														.addGroup(
																jPanel2Layout
																		.createSequentialGroup()
																		.addComponent(
																				fecha,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				71,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				jLabel5))
														.addComponent(
																listadoEgreso,
																0,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE))
										.addContainerGap(60, Short.MAX_VALUE)));
		jPanel2Layout
				.setVerticalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel3)
														.addComponent(
																fecha,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel5))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel4)
														.addComponent(
																listadoEgreso,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
																.addGroup(
																		layout.createSequentialGroup()
																				.addComponent(
																						jPanel2,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addContainerGap())
																.addGroup(
																		javax.swing.GroupLayout.Alignment.TRAILING,
																		layout.createSequentialGroup()
																				.addComponent(
																						jPanel1,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addContainerGap()))
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addComponent(
																		botonCancelar)
																.addGap(18, 18,
																		18)
																.addComponent(
																		botonAceptar)
																.addContainerGap()))));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(jPanel2,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jPanel1,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(botonAceptar)
												.addComponent(botonCancelar))
								.addContainerGap(
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));

		pack();
	}// </editor-fold>

	private void botonAgregarActionPerformed(java.awt.event.ActionEvent evt) {
		if (tipoEgreso.equals("")) {
			JOptionPane.showMessageDialog(this,
					ErrorUtils.SELECCIONE_TIPO_EGRESO, "ERROR",
					JOptionPane.ERROR_MESSAGE);
		} else if (tipoAlimento.equals("")) {
			JOptionPane.showMessageDialog(this,
					ErrorUtils.SELECCIONE_TIPO_ALIMENTO, "ERROR",
					JOptionPane.ERROR_MESSAGE);
		} else if (cantidad.getText().equals("")) {
			JOptionPane.showMessageDialog(this, ErrorUtils.CANTIDAD_VACIA,
					"ERROR", JOptionPane.ERROR_MESSAGE);
		} else if (!StringUtils.isNumber(cantidad.getText())) {
			JOptionPane.showMessageDialog(this, ErrorUtils.CANTIDAD_INVALIDA,
					"ERROR", JOptionPane.ERROR_MESSAGE);
		} else {
			try {
				int resultado = GestionAlimentosINT.validarStock(tipoAlimento,
						cantidad.getText());

				if (resultado != -1) {
					JOptionPane
							.showMessageDialog(
									null,
									ErrorUtils.CANTIDAD_ALIMENTO_MENOR_1
											+ tipoAlimento
											+ ErrorUtils.CANTIDAD_ALIMENTO_MENOR_2
											+ resultado + " "
											+ unidadAlimento, "ERROR",
									JOptionPane.ERROR_MESSAGE);
				} else {
					tabla[i][0] = tipoAlimento;
					tabla[i][1] = cantidad.getText();
					tabla[i][2] = unidadAlimento;
					tabla[i][3] = tipoEgreso;
					i++;
					tablaEgresos
							.setModel(new javax.swing.table.DefaultTableModel(
									tabla, new String[] { "Alimento",
											"Cantidad", "Unidad", "Egreso" }) {
								private static final long serialVersionUID = 1L;

								@Override
								public boolean isCellEditable(int fila,
										int columna) {
									return false;
								}
							});
					cantidad.setText("");
					listadoAlimentos.setSelectedIndex(0);
					DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
					tcr.setHorizontalAlignment(SwingConstants.CENTER);
					tablaEgresos.getColumnModel().getColumn(0)
							.setCellRenderer(tcr);
					tablaEgresos.getColumnModel().getColumn(1)
							.setCellRenderer(tcr);
					tablaEgresos.getColumnModel().getColumn(2)
							.setCellRenderer(tcr);
					tablaEgresos.getColumnModel().getColumn(3)
							.setCellRenderer(tcr);
					// unidad.setText("");
				}
			} catch (Exception e) {
				e.printStackTrace();
				JOptionPane.showMessageDialog(this,
						ErrorUtils.ERROR_INESPERADO, "ERROR INESPERADO",
						JOptionPane.ERROR_MESSAGE);
				this.dispose();
			}
		}

	}

	private void listadoAlimentosItemStateChanged(java.awt.event.ItemEvent evt) {
		try {
			if (evt.getStateChange() == 1) {
				if (evt.getItem() == "Seleccione un tipo") {
					unidad.setText("");
					tipoAlimento = "";
				} else {
					tipoAlimento = evt.getItem().toString();
					unidadAlimento = GestionAlimentosINT.getAlimentoByTipo(
							evt.getItem().toString()).get("unidad");
					unidad.setText(unidadAlimento);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			JOptionPane.showMessageDialog(this, ErrorUtils.ERROR_INESPERADO,
					"ERROR INESPERADO", JOptionPane.ERROR_MESSAGE);
			this.dispose();
		}
	}

	private void botonEliminarActionPerformed(java.awt.event.ActionEvent evt) {
		try {
			int indice = tablaEgresos.getSelectedRow();

			if (indice == -1) {
				JOptionPane.showMessageDialog(this,
						ErrorUtils.ELIMINAR_ELEMENTO_TABLA, "ERROR",
						JOptionPane.ERROR_MESSAGE);
			} else if (StringUtils.isNullOrBlank(tabla[indice][0])) {
				JOptionPane.showMessageDialog(this,
						ErrorUtils.ELIMINAR_ELEMENTO_TABLA, "ERROR",
						JOptionPane.ERROR_MESSAGE);
			} else {
				tabla[indice][0] = "";
				tabla[indice][1] = "";
				tabla[indice][2] = "";
				tabla[indice][3] = "";

				int j;

				for (j = indice; j < i; j++) {
					tabla[j][0] = tabla[j + 1][0];
					tabla[j][1] = tabla[j + 1][1];
					tabla[j][2] = tabla[j + 1][2];
					tabla[j][3] = tabla[j + 1][3];
				}
				tabla[j][0] = "";
				tabla[j][1] = "";
				tabla[j][2] = "";
				tabla[j][3] = "";

				i--;

				tablaEgresos.setModel(new javax.swing.table.DefaultTableModel(
						tabla, new String[] { "Alimento", "Cantidad", "Unidad",
								"Egreso" }) {
					private static final long serialVersionUID = 1L;

					@Override
					public boolean isCellEditable(int fila, int columna) {
						return false;
					}
				});
				cantidad.setText("");
				DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
				tcr.setHorizontalAlignment(SwingConstants.CENTER);
				tablaEgresos.getColumnModel().getColumn(0).setCellRenderer(tcr);
				tablaEgresos.getColumnModel().getColumn(1).setCellRenderer(tcr);
				tablaEgresos.getColumnModel().getColumn(2).setCellRenderer(tcr);
				tablaEgresos.getColumnModel().getColumn(3).setCellRenderer(tcr);
			}
		} catch (Exception e) {
			e.printStackTrace();
			JOptionPane.showMessageDialog(this, ErrorUtils.ERROR_INESPERADO,
					"ERROR INESPERADO", JOptionPane.ERROR_MESSAGE);
			this.dispose();
		}
	}

	private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {
		try {

			String valida = DateUtils.esValida(fecha.getText());

			if (!valida.equals("")) {
				JOptionPane.showMessageDialog(this, valida, "ERROR",
						JOptionPane.WARNING_MESSAGE);
			} else if (tabla[0][0].equals("")) {
				JOptionPane.showMessageDialog(this, ErrorUtils.TABLA_VACIA,
						"ERROR", JOptionPane.ERROR_MESSAGE);
			} else {

				int aux = 0;

				ArrayList<Map<String, String>> listado = new ArrayList<Map<String, String>>();
				while (!tabla[aux][0].equals("")) {
					Map<String, String> egreso = new HashMap<String, String>();
					egreso.put("id", tabla[aux][0]);
					egreso.put("cantidad", tabla[aux][1]);
					egreso.put("tipoMovimiento",
							TipoMovimientoEnum.getIdTipo(tabla[aux][3]));
					listado.add(egreso);
					aux++;
				}
				GestionAlimentosINT.egresoAlimentos(listado, fecha.getText(),
						this);
			}

		} catch (Exception e) {
			e.printStackTrace();
			JOptionPane.showMessageDialog(this, ErrorUtils.ERROR_INESPERADO,
					"ERROR INESPERADO", JOptionPane.ERROR_MESSAGE);
			this.dispose();
		}

	}

	private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {
		if (JOptionPane.showConfirmDialog(this, ErrorUtils.CANCELAR,
				"CANCELAR", JOptionPane.YES_NO_OPTION) == 0)
			this.dispose();
	}

	private void listadoEgresoItemStateChanged(java.awt.event.ItemEvent evt) {
		if (evt.getStateChange() == 1) {
			if (evt.getItem() == "Seleccione un tipo") {
				tipoEgreso = "";
			} else
				tipoEgreso = evt.getItem().toString();
		}
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new EgresoAlimentos().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify
	private javax.swing.JButton botonAceptar;
	private javax.swing.JButton botonAgregar;
	private javax.swing.JButton botonCancelar;
	private javax.swing.JButton botonEliminar;
	private javax.swing.JTextField cantidad;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JComboBox listadoAlimentos;
	private javax.swing.JTable tablaEgresos;
	private javax.swing.JLabel unidad;
	private String[][] tabla;
	private String tipoAlimento;
	private String unidadAlimento;
	private String tipoEgreso;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JComboBox listadoEgreso;
	private javax.swing.JTextField fecha;
	private int i;
	// End of variables declaration
}
